public class Test1 {
    //求斐波那契数列的第n项。(迭代实现) 1 1 2 3 5 8
    public static int fiboNum(int n){
        int sum = 0;
        if( n == 1 || n == 2){
            return 1;
        }
            sum = fiboNum(n-2) + fiboNum(n-1);
        return sum;
    }
    public static void main1(String[] args) {
        System.out.println(fiboNum(6));
    }
    public static int sum(int n){
        int sum = 0;
        //22 --> 22%10 +22/10%10
        if(n<10){
            return n;
        }
        sum = sum(n/10)+sum(n%10);
        return sum;
    }
public static int fiboNum2(int n){ // 迭代    交换位置
        int sum = 0;
        int a = 1;
        int b = 1;
    for (int i = 3; i <= n; i++) {
        sum = a+b;
        a = b;
        b = sum;
    }
        return sum;
}
public static void print1(int n){
        if(n<10){
            System.out.print(" "+n);
            return;
        }
        print1(n/10);
    System.out.print(" "+n%10);
}
public static int sum11(int n){
        int sum = 0;
        if (n==1){
            return 1;
        }
        sum = n + sum11(n-1);
        return sum;
}
public static int factorial(int n){
        int multiplication = 1;
        if(n ==1){
            return 1;
        }
        multiplication = n * factorial(n-1);
        return multiplication;
}
    public static void main(String[] args) {
        System.out.println(factorial(3));
    }
}
